package com.dave.dubbo.nacos.provider.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import com.dave.dubbo.provider.api.MessageService_2_7_8;
import com.dave.dubbo.provider.api.entity.UserTest;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Slf4j
@Component
@DubboService(version = "1.0.0")
public class MessageServiceImpl implements MessageService_2_7_8 {


    @Value("${spring.application.name}")
    private String serviceName;

    @Override
    public String sayHello(String content) {
        log.info("收到请求参数: {}", content);
        return String.format("[%s] : Hello, %s", serviceName, content);
    }


    @Override
    public String sayHello(String name, String msg) {
        log.info("收到请求参数: {} {}", name, msg);
        return String.format("[%s] : Hello, %s", name, msg);
    }

    @Override
    public String sayHelloInt(int content) {
        return String.format("[%s] : Hello, %s", serviceName, content);
    }

    @Override
    public String sayHelloUser(UserTest user) {
        user.setDatetime(DateUtil.formatDateTime(new Date()));
        return String.format("收到消息%s,时间为：%s", user.getName(), DateUtil.formatDateTime(new Date()));
    }

    @Override
    public String sayHelloUser(UserTest user, UserTest userTest2) {
        user.setDatetime(DateUtil.formatDateTime(new Date()));
        return String.format("收到消息1%s ,收到消息2 %s", user.getName(), userTest2.getName());
    }


    @Override
    public String sayHelloMap(Map<String, String> map) {
        log.info("收到消息请求," + System.currentTimeMillis());
        return MapUtil.join(map, ";", "=");
    }

    @Override
    public Map sendMap(Map map) {
        log.info("sendMap:收到消息请求," + System.currentTimeMillis());
        return map;
    }
}
